import Vue from 'vue'
import Router from 'vue-router'

Vue.use(Router)

/* Layout */
import Layout from '@/layout'

/**
 * Note: sub-menu only appear when route children.length >= 1
 * Detail see: https://panjiachen.github.io/vue-element-admin-site/guide/essentials/router-and-nav.html
 *
 * hidden: true                   if set true, item will not show in the sidebar(default is false)
 * isShow: true               if set true, will always show the root menu
 *                                if not set isShow, when item has more than one children route,
 *                                it will becomes nested mode, otherwise not show the root menu
 * redirect: noRedirect           if set noRedirect will no redirect in the breadcrumb
 * name:'router-name'             the name is used by <keep-alive> (must set!!!)
 * meta : {
		roles: ['admin','editor']    control the page roles (you can set multiple roles)
		title: 'title'               the name show in sidebar and breadcrumb (recommend set)
		icon: 'svg-name'/'el-icon-x' the icon show in the sidebar
		noCache: true                if set true, the page will no be cached(default is false)
		affix: true                  if set true, the tag will affix in the tags-view
		breadcrumb: false            if set false, the item will hidden in breadcrumb(default is true)
		activeMenu: '/example/list'  if set path, the sidebar will highlight the path you set
	}
 */

/**
 * constantRoutes
 * a base page that does not have permission requirements
 * all roles can be accessed
 */
export const constantRoutes = [{
    path: '/redirect',
    component: Layout,
    hidden: true,
    children: [{
      path: '/redirect/:path(.*)',
      component: () => import('@/views/redirect/index')
    }]
  },
  {
    path: '/login',
    component: () => import('@/views/login/index'),
    hidden: true
  },
  {
    path: '/',
    component: Layout,
    redirect: '/home',
    children: [{
      path: 'home',
      component: () => import('@/views/home/index'),
      meta: {
        title: [{
            langId: 1,
            name: '首页'
          },
          {
            langId: 2,
            name: 'home'
          },
          {
            langId: 3,
            name: 'Главн страниц'
          },
          {
            langId: 4,
            name: 'Bosh sahifa'
          },
          {
            langId: 5,
            name: 'Үй'
          }
        ],
        icon: 'home',
        affix: true
      }
    }]
  },
  {
    path: '/auth-redirect',
    component: () => import('@/views/login/auth-redirect'),
    hidden: true
  },
  {
    path: '/404',
    component: () => import('@/views/error-page/404'),
    hidden: true
  },
  {
    path: '/401',
    component: () => import('@/views/error-page/401'),
    hidden: true
  },
  {
    path: '/all-hidden-page',
    component: Layout,
    redirect: '/all-hidden-page/personal-center',
    hidden: true,
    children: [{
        path: 'personal-center',
        component: () => import('@/views/personal-center'),
        meta: {
          title: [{
              langId: 1,
              name: '个人中心'
            },
            {
              langId: 2,
              name: 'Personal Center'
            },
            {
              langId: 3,
              name: ' Индивидуальный центр'
            },
            {
              langId: 4,
              name: 'Shaxsiy markaz'
            },
            {
              langId: 5,
              name: 'Жеке орталық'
            }
          ]
        }
      },


      {
        path: '/car-series-info',
        component: () => import('@/views/pages/basic-manager/vehicle-Inventory-manager/car-series-info'),
        meta: {
          title: [{
              langId: 1,
              name: '车系管理'
            },
            {
              langId: 2,
              name: 'Vehicle series management'
            },
            {
              langId: 3,
              name: 'Управление автомобилем'
            },
            {
              langId: 4,
              name: 'Avtomobilni boshqarish'
            },
            {
              langId: 5,
              name: 'Флотты басқару'
            },
          ],
        },
      }, {
        path: '/vehicle-manager-info',
        component: () => import('@/views/pages/basic-manager/vehicle-Inventory-manager/vehicle-manager-info'),
        meta: {
          title: [{
              langId: 1,
              name: '车型管理'
            },
            {
              langId: 2,
              name: 'Vehicle model management'
            },
            {
              langId: 3,
              name: 'Управление автомобилем'
            },
            {
              langId: 4,
              name: 'Avtomobilni boshqarish'
            },
            {
              langId: 5,
              name: 'Көлік құралдарының моделін басқару'
            },
          ],
        },
      },
    ]
  },

]

/**
 * asyncRoutes
 * the routes that need to be dynamically loaded based on user roles
 */
// const async_Routes = [

// ]

export const exampleRoutes = [{
  path: '/dashboard',
  component: Layout,
  meta: {
    title: [{
      langId: 1,
      name: '开发者管理'
    }, {
      langId: 2,
      name: 'Developer Management'
    }, {
      langId: 3,
      name: ' Управление разработчиками'
    }, {
      langId: 4,
      name: 'Dasturchilarni boshqarish'
    }],
    icon: 'password'
  },
  children: [{
      path: 'menu-manager',
      component: () => import('@/views/dashboard/menu-manager'),
      meta: {
        title: [{
            langId: 1,
            name: '菜单管理菜'
          }, {
            langId: 2,
            name: 'menu management'
          },
          {
            langId: 3,
            name: ' Меню Управление'
          },
          {
            langId: 4,
            name: 'Menyu boshqaruvi'
          }
        ]
      }
    },
    {
      path: 'table_header_manage',
      component: () => import('@/views/dashboard/table_header_manage'),
      meta: {
        title: [{
            langId: 1,
            name: '表头管理'
          }, {
            langId: 2,
            name: 'menu management'
          },
          {
            langId: 3,
            name: ' Меню Управление'
          },
          {
            langId: 4,
            name: 'Menyu boshqaruvi'
          }
        ]
      }
    },
    {
      path: '/authorization',
      component: () => import('@/views/pages/system-manager/authorization'),
      meta: {
        title: [{
            langId: 1,
            name: '权限设置'
          }, {
            langId: 2,
            name: 'Permission setting'
          },
          {
            langId: 3,
            name: 'Доступ установлен.'
          },
          {
            langId: 4,
            name: 'Ruxsat moslamalari'
          },
          {
            langId: 5,
            name: 'Рұқсат параметрлері'
          }
        ]
      }
    },

  ]
}, ]

// export const asyncRoutes = async_Routes;

// process.env.NODE_ENV
const createRouter = () => new Router({
  // mode: 'history', // require service support
  scrollBehavior: () => ({
    y: 0
  }),
  routes: constantRoutes
})

const router = createRouter()

// Detail see: https://github.com/vuejs/vue-router/issues/1234#issuecomment-357941465
export function resetRouter() {
  const newRouter = createRouter()
  router.matcher = newRouter.matcher // reset router
}

export const loadView = (view) => {
  return (resolve) => require([`@/views/${view}.vue`], resolve)
}

export default router
